<template>
  <el-dialog :visible.sync="dialogVisible" width="60%" top="5%" :before-close="handleClose" append-to-body :append-to-body="true"
    :close-on-click-modal="false">
    <template slot="title">
      <el-divider content-position="left"><span class="title"> 交班信息</span></el-divider>
    </template>
    <el-row :gutter="20" style="heigth:80%">
      <el-col :span="16">
        <div class="block">
          <el-date-picker v-model="timeRange" type="datetimerange" readonly range-separator="至" start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </div>
        <el-row>
          <el-tabs type="border-card" v-model="currTab" @tab-click="tabChange">
            <el-tab-pane label="交班对账单" name="交班对账单">
              <el-row :gutter="20">
                <el-col :span="8">
                  <div class="text item title">
                    【账目信息】
                  </div>
                  <div class="text item">
                    房费金额：<el-link :underline="false" type="primary" @click.stop="accountDetail(4,'')">{{dataMap['房费']==null?0:dataMap['房费']}}</el-link>
                  </div>
                  <div class="text item">
                    消费金额：<el-link :underline="false" type="primary" @click.stop="accountDetail(2,'')">{{dataMap['消费']==null?0:dataMap['消费']}}</el-link>
                  </div>
                  <div class="text item">
                    POS商品：<el-link :underline="false" type="primary" @click.stop="cashBillsDataDetail()">{{dataMap['消费点']==null?0:dataMap['消费点']}}</el-link>
                  </div>
                  <div class="text item">
                    非住客账：<el-link :underline="false" type="primary" @click.stop="noninoutDataDetail()">{{dataMap['非住客账']==null?0:dataMap['非住客账']}}</el-link>
                  </div>
                  <div class="text item">
                    红冲金额：<el-link :underline="false" type="primary" @click.stop="accountDetail(9,'')">-{{dataMap['红冲']==null?0:dataMap['红冲']}}</el-link>
                  </div>
                  <div class="text item">
                    优惠金额：<el-link :underline="false" type="primary" @click.stop="accountDetail(13,'')">-{{dataMap['优惠金额']==null?0:dataMap['优惠金额']}}</el-link>
                  </div>
                  <div class="text item">
                    会员充值：0
                  </div>
                  <div class="text item">
                    商品退货：<el-link :underline="false" type="primary" @click.stop="roomshoprecordDetail(2)">-{{dataMap['商品退货']==null?0:dataMap['商品退货']}}</el-link>
                  </div>
                  <div class="text item">
                    应收合计：{{dataMap['和']}}
                  </div>
                  <el-divider></el-divider>
                  <div class="text item" v-for="(item,key) in countMap" :key="key">
                    <div v-if="key!='和'">
                      <el-link :underline="false" type="primary" @click.stop.prevent="accountDetail('',key)">{{key+"："+item}}</el-link>
                    </div>
                  </div>
                  <div class="text item">
                    实收合计：{{payDataMap['和'] + depositMap['和'] }}
                  </div>
                  <el-divider></el-divider>
                  <div class="text item title">
                    【商品销售分析】
                  </div>
                  <div class="text item">
                    房间商品：{{dataMap['消费']==null?0:dataMap['消费']}}
                  </div>
                  <div class="text item">
                    POS商品：{{dataMap['消费点']==null?0:dataMap['消费点']}}
                  </div>
                  <div class="text item">
                    商品销售合计：{{(dataMap['消费']==null?0:dataMap['消费']) + (dataMap['消费点']==null?0:dataMap['消费点'])}}
                  </div>
                </el-col>

                <el-col :span="8">
                  <div class="title text item">
                    【交班转交押金】
                  </div>
                  <div class="text item title">
                    上班转交押金：{{nextDeposit}}
                  </div>
                  <div class="text item" v-for="(item,key) in upperDepositMap" :key="key" v-if="isFirst==1">
                    <span v-if="key!='和'">{{key+"："+item}}</span>
                  </div>
                  <el-divider></el-divider>
                  <div class="text item title">
                    本班实收押金：
                  </div>
                  <div class="text item " v-for="(item,key) in depositMap" :key="key">
                    <div v-if="key!='和'">
                      <el-link :underline="false" type="primary" @click.stop="accountDetail(3,key)">{{key+"："+item}}</el-link>
                    </div>
                  </div>
                  <div class="text item">
                    合计：{{depositMap['和']}}
                  </div>
                  <el-divider></el-divider>
                  <div class="text item title">
                    应转下班押金：
                  </div>
                  <div v-if="isFirst==1">
                    <div class="text item" v-for="(item,key) in nextDepositMap" :key="key">
                      <span v-if="key!='和'">{{key+"："+item}}</span>
                    </div>

                  </div>
                  <div class="text item" v-if="isFirst==1">
                    合计：{{nextDepositMap['和']}}
                  </div>

                  <div class="text item " v-for="(item,key) in depositMap" :key="key" v-if="isFirst==0">
                    <div v-if="key!='和'">
                      {{key+"："+item}}
                    </div>
                  </div>
                  <div class="text item" v-if="isFirst==0">
                    合计：{{depositMap['和']}}
                  </div>

                </el-col>
                <el-col :span="8">
                  <div class="text item title">
                    【交班转交营业款】
                  </div>
                  <div class="text item title">
                    上班转交营业款：{{nextMoney}}
                  </div>
                  <div class="text item" v-for="(item,key) in upperMoneyMap" :key="key" v-if="isFirst==1">

                    <span v-if="key!='和'">{{key+"："+item}}</span>
                  </div>
                  <el-divider></el-divider>
                  <div class="text item title">
                    本班实收营业款
                  </div>
                  <div class="text item" v-for="(item,key) in payDataMap" :key="key">
                    <div v-if="key!='和'">
                      <el-link :underline="false" type="primary" @click.stop.prevent="accountDetail(7654,key)">{{key+"："+item}}</el-link>
                    </div>
                  </div>
                  <div class="text item">
                    实收合计：{{payDataMap['和']}}
                  </div>
                  <el-divider></el-divider>
                  <div class="text item title">
                    应转下班营业款：
                  </div>
                  <div v-if="isFirst==1">
                    <div class="text item" v-for="(item,key) in nextMoneyMap" :key="key">
                      <span v-if="key!='和'">{{key+"："+item}}</span>
                    </div>
                  </div>
                  <div class="text item" v-if="isFirst==1">
                    实收合计：{{nextMoneyMap['和']}}
                  </div>
                  <div class="text item" v-for="(item,key) in payDataMap" :key="key" v-if="isFirst==0">
                    <div v-if="key!='和'">
                      {{key+"："+item}}
                    </div>
                  </div>
                  <div class="text item" v-if="isFirst==0">
                    实收合计：{{payDataMap['和']}}
                  </div>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="商品列表" name="商品列表">
              <div class="title"> 【本班销售商品】</div>
              <el-table :data="shiftWorkGoodsTable" border style="width: 100%">
                <el-table-column prop="name" label="名字" width="180">
                </el-table-column>
                <el-table-column prop="closed" label="已结" width="180">
                </el-table-column>
                <el-table-column prop="open" label="未结">
                </el-table-column>
                <el-table-column label="合计">
                  <template slot-scope="scope">
                    {{scope.row.closed + scope.row.open}}
                  </template>
                </el-table-column>
              </el-table>
              <el-divider></el-divider>

              <div class="title"> 【商品库存信息】</div>
              <el-table :data="goodsList" border style="width: 100%">
                <el-table-column prop="shopName" label="名字">
                </el-table-column>
                <el-table-column prop="saleNum" label="整体销售量">
                </el-table-column>
                <el-table-column prop="stockNum" label="库存">
                </el-table-column>
              </el-table>

            </el-tab-pane>

          </el-tabs>
        </el-row>


      </el-col>
      <el-col :span="8">
        <div>
          <div>
            <div>
              <h3>转交营业款：{{parseFloat(isFirst==0?this.payDataMap['和']:this.nextMoneyMap['和'])-parseFloat(sum(this.values1))}}</h3>
            </div>
            <el-form :inline="true">
              <el-form-item v-if="key!='和'" :label="'上交'+key+'：'" v-for="(item,key) in values1" :key="key">
                <el-input v-model="values1[key]" :max="1000"></el-input>
              </el-form-item>
            </el-form>

            <div>
              <h3>转交押金：{{parseFloat(isFirst==0?this.depositMap['和']:this.nextDepositMap['和'])-parseFloat(sum(this.values2))}}</h3>
            </div>

            <el-form :inline="true">
              <el-form-item v-if="key!='和'" :label="'上交'+key+'：'" v-for="(item,key) in values2" :key="key">
                <el-input v-model="values2[key]" :max="depositMap[key]"></el-input>
              </el-form-item>
            </el-form>

            <p class="danger">
              留给下班的营业款=本班实收营业款+上班转入营业款<br>
              留给下班的押金=本班实收押金+上班转入押金
            </p>

            <el-row style="margin-top:24px">
              <el-divider content-position="left"><span class="title"> 打印配置</span></el-divider>
            </el-row>
            <el-checkbox v-model="checkbox">打印商品报表</el-checkbox>
            <el-checkbox v-model="checkbox2">打印费用明细</el-checkbox>
          </div>
          <div style="margin-top:24px"></div>
          <el-divider></el-divider>
          <el-form v-if="!detailModel" ref="dataForm" :model="dataForm" label-width="80px">

            <el-form-item label="班次">
              <el-select v-model="dataForm.handType" placeholder="请选择" >
                <el-option v-for="item in shiftoverType" :key="item.id" :label="item.label" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="接班">
              <el-select v-model="dataForm.successionUserId" placeholder="请选择">
                <el-option v-for="item in userList" :key="item.userId" :label="item.username" :value="item.userId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="密码">
              <el-input type="password" v-model="dataForm.password" autocomplete="off"></el-input>
            </el-form-item>

          </el-form>

          <el-button type="primary" @click="print()">打印交班汇总表</el-button>
          <el-button type="info" v-if="!detailModel" @click="submitShiftWorkData()">交班并退出</el-button>
          <div v-if="!detailModel"><br></div>
          <el-button v-if="isAuth('hotel:thotelfloorroomcheckinaccounting:info2')" type="primary" @click="$refs.jba5_mx.init()">打印交班明细表</el-button>
        </div>
      </el-col>
    </el-row>
    <accountData v-if="accountDataVisible" ref="accountData"></accountData>
    <cashBillsData v-if="cashBillsDataVisible" ref="cashBillsData"></cashBillsData>
    <noninoutData v-if="noninoutDataVisible" ref="noninoutData"></noninoutData>
    <roomshoprecord v-if="roomshoprecordVisible" ref="roomshoprecord"></roomshoprecord>
    <jb58 v-if="active=='jb58'" v-show="false" id="jb58" ref="jb58" :handType="dataForm.handType" :shiftoverType="shiftoverType" :dataMap="dataMap" :nextDeposit="nextDeposit"
      :nextMoney="nextMoney" :upperDepositMap="upperDepositMap" :depositMap="depositMap" :nextDepositMap="nextDepositMap"
      :upperMoneyMap="upperMoneyMap" :payDataMap="payDataMap" :nextMoneyMap="nextMoneyMap" :startTime="startTime"
      :endTime="endTime" :user="user" :seller="seller" :isFirst="isFirst" :username="username==''?user.username:username"
      :goodsPrint="checkbox" :goods="shiftWorkGoodsTable"></jb58>
    <jb80 v-if="active=='jb80'" v-show="false" id="jb80" ref="jb80" :handType="dataForm.handType" :shiftoverType="shiftoverType" :dataMap="dataMap" :nextDeposit="nextDeposit"
      :nextMoney="nextMoney" :upperDepositMap="upperDepositMap" :depositMap="depositMap" :nextDepositMap="nextDepositMap"
      :upperMoneyMap="upperMoneyMap" :payDataMap="payDataMap" :nextMoneyMap="nextMoneyMap" :startTime="startTime"
      :endTime="endTime" :user="user" :seller="seller" :isFirst="isFirst" :username="username==''?user.username:username"
      :goodsPrint="checkbox" :goods="shiftWorkGoodsTable"></jb80>
    <jba5 v-if="active=='jba5'" v-show="false" id="jba5" ref="jba5" :handType="dataForm.handType" :shiftoverType="shiftoverType" :dataMap="dataMap" :nextDeposit="nextDeposit"
      :nextMoney="nextMoney" :upperDepositMap="upperDepositMap" :depositMap="depositMap" :nextDepositMap="nextDepositMap"
      :upperMoneyMap="upperMoneyMap" :payDataMap="payDataMap" :nextMoneyMap="nextMoneyMap" :startTime="startTime"
      :endTime="endTime" :user="user" :seller="seller" :isFirst="isFirst" :username="username==''?user.username:username"
      :goodsPrint="checkbox" :goods="shiftWorkGoodsTable"></jba5>

    <jba5-mx ref="jba5_mx" v-show="false"
      :seller="seller"
      :startTime="startTime" :endTime="endTime" :handType="dataForm.handType" :shiftoverType="shiftoverType"
      :username="username || user.username"
      :fyPrint="checkbox2"

      :dataMap="dataMap" :countMap="countMap"
    />
  </el-dialog>
</template>
<script>
  import Moment from 'moment'
  import accountData from './accounts'
  import roomshoprecord from './roomshoprecord'
  import cashBillsData from './cashBillsList'
  import noninoutData from './nonInoutList'
  import {
    clearLoginInfo
  } from '@/utils'
  import jb58 from '../../../common/printtemplate/jiaoban_58mm';
  import jb80 from '../../../common/printtemplate/jiaoban_80mm';
  import jba5 from '../../../common/printtemplate/jiaoban_A5';
  import {
    getLodop
  } from '../../../../utils/lodop';

  import jba5_mx from '@/views/common/printtemplate/jiaoban_A5_mx'

  export default {
    data() {
      return {
        dataForm: {
          successionUserId: '',
          handType: '',
          password: '',
        },
        shiftoverType: {

        },
        userList: [],
        countMap: {},
        dialogVisible: false,
        dataMap: {},
        payDataMap: {},
        payDataMapSum: 0,
        depositMap: {},
        startTime: '',
        endTime: '',
        timeRange: [this.startTime, this.endTime],
        isFirst: '',
        values1: {},
        values2: {},
        upperMoneyMap: {},
        upperDepositMap: {},
        nextMoneyMap: {},
        nextDepositMap: {},
        accountDataVisible: false,
        cashBillsDataVisible: false,
        roomshoprecordVisible: false,
        noninoutDataVisible: false,
        nextMoney: 0,
        nextDeposit: 0,
        currTab: "交班对账单",
        shiftWorkGoodsTable: [],
        goodsList: [],
        checkbox: true,
        detailModel: false,
        active: '',
        printconfig: {},
        user: {},
        seller: {},
        username: '',

        checkbox2: false
      }
    },
    components: {
      accountData,
      roomshoprecord,
      cashBillsData,
      noninoutData,
      jb58,
      jb80,
      jba5,

      'jba5-mx': jba5_mx
    },
    methods: {
      init() {
        this.dialogVisible = true;
        this.detailModel = false;
        this.getUser();
        this.getTime();
        this.currTab = "交班对账单"
        this.getPrintMsg()
        this.$comReq.reqDictionaryData("shiftover")
          .then(({
            data
          }) => {
            this.shiftoverType = data.page.list
            this.searchTodayHandType(this.shiftoverType);
          });

        this.$comReq.reqMerchantOperator()
          .then(({
            data
          }) => {
            this.userList = data.list
          });
      },
      searchTodayHandType(list){
        //查询今日交班
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelshiftwork/todayHandType'),
          method: 'get',
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            list.map(item=>({
              ...item,
              disabled:data.list.indexOf(item.id) != -1
            }))
          } else {

          }
        })
      },
      detailInit(startTime, endTime, userName) {
        this.dialogVisible = true
        this.startTime = startTime;
        this.endTime = endTime;
        this.getUser();
        this.username = userName
        this.$set(this.timeRange, 0, this.startTime)
        this.$set(this.timeRange, 1, this.endTime)
        this.detailModel = true
        this.getData();

        this.currTab = "交班对账单"
        this.getPrintMsg();
        this.getGoodsList();

      },
      handleClose(done) {
        // this.$confirm('确认关闭？')
        //   .then(_ => {
        //     done();
        //   })
        //   .catch(_ => {});
        done();
      },
      sum(map) {
        var sum = 0;
        for (let key in map) {
          if (key != '和')
            sum += parseFloat(map[key] == '' ? 0 : map[key])
        }
        return sum;
      },
      getTime() {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelshiftwork/getTime'),
          method: 'get',
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.startTime = Moment(data.startTime).format('YYYY-MM-DD HH:mm:ss');
            this.endTime = Moment(data.endTime).format('YYYY-MM-DD HH:mm:ss');
            this.$set(this.timeRange, 0, this.startTime)
            this.$set(this.timeRange, 1, this.endTime)
            this.$forceUpdate();
            this.getData();
            this.getGoodsList();
          } else {

          }
        })
      },
      getUser() {

        this.$http({
          url: this.$http.adornUrl('/hotel/thotelprinttemplate/printInfo'),
          method: 'get',
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            console.log(data)
            this.user = data.user
            this.seller = data.seller
          } else {

          }
        })
      },
      getPrintMsg() {

        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelprinttemplate/info/5`),
          method: 'get'
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.printconfig = data.tHotelPrintTemplate;
          }
        });

      },
      print() {
        this.CreateOneFormPage();

        // if (s == 0) {
        //   LODOP.PRINT() //直接打印
        // }
        // if (s == 1) {
        //   LODOP.PREVIEW() //打印预览
        // }
        // if (s == 2) {
        //   LODOP.PRINT_SETUP() //打印维护
        // }
        // if (s == 3) {
        //   LODOP.PRINT_DESIGN() //打印设计
        // }

        LODOP.SET_PRINT_COPIES(this.printconfig.printSum);
        console.log(LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint));
        if (this.printconfig.preview) {
          if (LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint)) {
            LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint);
            // LODOP.PRINT();
            this.$nextTick(() => {
              // LODOP.PRINT_DESIGN();
              LODOP.PRINT();
              this.active = ''
            })


          } else {
            LODOP.SET_PRINTER_INDEXA(0);
            // LODOP.PRINT();
            this.$nextTick(() => {
              // LODOP.PRINT_DESIGN();
              LODOP.PRINT();
              this.active = ''
            })
          }
        } else {
          if (LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint)) {
            LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint);
            this.$nextTick(() => {
              LODOP.PREVIEW();
              this.active = ''
            })

            // LODOP.PRINT_DESIGN();
          } else {
            LODOP.SET_PRINTER_INDEXA(0);
            this.$nextTick(() => {
              LODOP.PREVIEW();
              this.active = ''
            })
            // LODOP.PRINT_DESIGN();
          }
        }




      },
      CreateOneFormPage() {

        LODOP = getLodop();
        if (!LODOP) {
          this.$alert(
            `<br><font color='#FF00FF'>CLodop云打印服务(localhost本地)未安装启动!点击这里<a href='http://www.lodop.net/download/CLodop_Setup_for_Win32NT_4.088Extend.zip' download target='_self'>执行安装</a>,安装后请刷新页面。</font>`,
            '安装', {
              confirmButtonText: '确定',
              dangerouslyUseHTMLString: true
            }
          );
          return;
        }
        //样式
        //   var strStyleCSS = " <link href='https://ebooking.qlan99.com/css/print.css' type='text/css' rel='stylesheet'> ";



        var olstyle1 = '<!DOCTYPE html><html lang="zh-CN"><head>' + '' + '</head>' + ' <style> ' +
          'div{border:0!important}' + '</style>';
        var body = '';

        if (this.printconfig.specs === '58mm') {
          this.active = 'jb58'
          var olstyle2 = '<style> .print-wrap-normal{width:' + (58 + parseInt(this.printconfig.printContentOffset)) +
            'mm  !important}</style>';
          this.$nextTick(() => {
            body = olstyle1 + olstyle2 + '<body>' + this.$refs.jb58.$refs.container.innerHTML + '</body>';
            body += '</html>';
            LODOP.ADD_PRINT_HTM(0, this.printconfig.printPaperOffset, 1000, 2000, body); //增加超文本项
          })
          LODOP.SET_PRINT_PAGESIZE(0, '58mm', 4000, ''); //设定纸张大小
        }
        if (this.printconfig.specs === '80mm') {
          this.active = 'jb80'
          var olstyle2 = '<style> .print-wrap-normal{width:' + (80 + parseInt(this.printconfig.printContentOffset)) +
            'mm !important}</style>';
          this.$nextTick(() => {
            body = olstyle1 + olstyle2 + '<body>' + this.$refs.jb80.$refs.container.innerHTML + '</body>';
            body += '</html>';
            LODOP.ADD_PRINT_HTM(0, this.printconfig.printPaperOffset, 1000, 2000, body); //增加超文本项
          })
          LODOP.SET_PRINT_PAGESIZE(0, '80mm', 3000, ''); //设定纸张大小
        }
        if (this.printconfig.specs === 'A5') { //this.$refs.jba5.$refs.container.innerHTML

          // this.$refs.jba5.setData(this.dataMap,
          // this.nextDeposit,this.nextMoney,this.upperDepositMap,this.depositMap,
          // this.nextDepositMap,this.upperMoneyMap,this.payDataMap,this.nextMoneyMap)
          this.active = 'jba5'

          var olstyle2 = '<style> .print-wrap-normal{width:' + (210 + parseInt(this.printconfig.printContentOffset)) +
            'mm !important}</style>';

          this.$nextTick(() => {
            body = olstyle1 + olstyle2 + '<body>' + this.$refs.jba5.$refs.container.innerHTML + '</body>';
            body += '</html>';
            LODOP.ADD_PRINT_HTM(0, this.printconfig.printPaperOffset, 1000, 2000, body); //增加超文本项
          })
          LODOP.SET_PRINT_PAGESIZE(0, '210mm', 2000, ''); //设定纸张大小
        }




        // LODOP.PRINT_INITA(this.printconfig.printContentOffset, this.printconfig.printPaperOffset) //打印初始化、设定纸张整体偏移量、设定可视编辑区域大小

        LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', '100%'); //设置缩放
        // LODOP.PRINT_INIT('订单') //打印初始化
        LODOP.SET_PRINT_STYLE('FontSize', 12); //设置对象风格
        LODOP.SET_PRINT_STYLE('Bold', 1); ////设置对象风格
        LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, ''); //设置窗口
        LODOP.SET_PRINT_COPIES(this.printconfig.printSum); //设置打印次数
      },
      getData() {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelshiftwork/getShiftWorkData'),
          method: 'get',
          params: this.$http.adornParams({
            startTime: this.startTime,
            endTime: this.endTime,
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.dataMap = data.data
            this.countMap = data.countMap
            console.log(this.countMap)
            this.payDataMap = data.payData
            this.depositMap = data.deposit
            this.isFirst = data.isFirst
            this.upperMoneyMap = data.upperMoneyMap
            this.upperDepositMap = data.upperDepositMap
            this.nextMoneyMap = data.nextMoneyMap
            this.nextDepositMap = data.nextDepositMap
            this.nextMoney = data.nextMoney
            this.nextDeposit = data.nextDeposit
            if (this.isFirst == 0) {
              this.values1 = JSON.parse(JSON.stringify(this.payDataMap));
              this.values2 = JSON.parse(JSON.stringify(this.depositMap));
              for(var key in this.values2){
                this.values2[key] = 0
              }
            }
            if (this.isFirst == 1) {
              this.values1 = JSON.parse(JSON.stringify(this.nextMoneyMap));
              this.values2 = JSON.parse(JSON.stringify(this.nextDepositMap));
              for(var key in this.values2){
                this.values2[key] = 0
              }
            }



          } else {

          }
        })
      },
      submitShiftWorkData() {
        this.$confirm('确定交班？')
          .then(_ => {
            this.submit();
          }).catch(_ => {

          });


      },

      submit() {
        if (!this.dataForm.handType) {
          this.$message.error("请选择班次");
          return;
        }
        if (!this.dataForm.successionUserId) {
          this.$message.error("请选择接班人");
          return;
        }
        if (!this.dataForm.password) {
          this.$message.error("请输入密码");
          return;
        }

        var values1 = JSON.parse(JSON.stringify(this.payDataMap));
        var values2 = JSON.parse(JSON.stringify(this.depositMap));
        if (this.isFirst == 0) {
          for (let key1 in this.payDataMap) {
            values1[key1] = this.payDataMap[key1] - this.values1[key1]
          }
          for (let key1 in this.depositMap) {
            values2[key1] = this.depositMap[key1] - this.values2[key1]
          }
        }
        if (this.isFirst == 1) {
          for (let key1 in this.nextMoneyMap) {
            values1[key1] = this.nextMoneyMap[key1] - this.values1[key1]
          }
          for (let key1 in this.nextDepositMap) {
            values2[key1] = this.nextDepositMap[key1] - this.values2[key1]
          }
        }



        this.$http({
          url: this.$http.adornUrl('/hotel/thotelshiftwork/shiftWork'),
          method: 'post',
          data: this.$http.adornData({
            successionUserId: this.dataForm.successionUserId,
            handType: this.dataForm.handType,
            password: this.dataForm.password,
            workStartTime: this.startTime,
            shiftWorkTime: this.endTime,
            moneyValues: values1,
            depositValues: values2,
            nextMoney: parseFloat(this.isFirst == 0 ? this.payDataMap['和'] : this.nextMoneyMap['和']) -
              parseFloat(this.sum(this.values1)),
            nextDeposit: parseFloat(this.isFirst == 0 ? this.depositMap['和'] : this.nextDepositMap['和']) -
              parseFloat(this.sum(this.values2)),
            moneySum: this.values1['和'],
            depositSum: this.values2['和']
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "交接成功",
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.dialogVisible = false
                this.logout();
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        })
      },
      logout() {
        this.$http({
          url: this.$http.adornUrl('/sys/logout'),
          method: 'post',
          data: this.$http.adornData()
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            clearLoginInfo();
            this.$router.push({
              name: 'login'
            });
          }
        });
      },
      getGoodsList() {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelshiftwork/shiftWorkGoods'),
          method: 'get',
          params: this.$http.adornParams({
            startTime: this.startTime,
            endTime: this.endTime
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.shiftWorkGoodsTable = data.goods
            this.goodsList = data.goodsList
          } else {

          }
        })
      },
      accountDetail(payType, nowType) {
        this.accountDataVisible = true
        console.log(nowType)
        this.$nextTick(() => {
          this.$refs.accountData.init(payType, nowType, this.startTime, this.endTime)
        })
      },
      roomshoprecordDetail(type) {
        this.roomshoprecordVisible = true
        this.$nextTick(() => {
          this.$refs.roomshoprecord.init(type, this.startTime, this.endTime)
        })
      },
      cashBillsDataDetail() {
        this.cashBillsDataVisible = true
        this.$nextTick(() => {
          this.$refs.cashBillsData.init(this.startTime, this.endTime)
        })
      },

      noninoutDataDetail() {
        this.noninoutDataVisible = true
        this.$nextTick(() => {
          this.$refs.noninoutData.init(this.startTime, this.endTime)
        })
      },
      tabChange(tab) {
        if (tab.name == "交班对账单") {
          this.getData();
        }
        if (tab.name == "商品列表") {
          this.getGoodsList();
        }
      }
    },
    mounted() {}
  };
</script>

<style lang="scss" scoped>
  .el-row,
  .el-divider,
  .block {
    margin-bottom: 12px;
  }

  .el-range-editor {
    width: 100%;
  }

  .text {
    font-size: 14px;
  }

  .danger {
    color: #F56C6C;
  }

  .item {
    margin-bottom: 12px;
  }

  .title {
    font-size: 14px;
    font-weight: bold;
  }
</style>
